﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using ActivitiesControl.Domain.Model.Entities;
using ActivitiesControl.Domain.Services;
using ActivitiesControl.Domain.Model.VOs;

namespace ActivitiesControl.Services.WCF
{
    public class ActivitiesControlServices
		: IActivitiesControlServices
    {
		public ActivitiesControlServices() 
		{
			activityService = ServicesProvider.GetManageActivityService();
			userService = ServicesProvider.GetUserServices();
		}

		#region Activity
		private IManageActivityService activityService;

		public IEnumerable<Customer> GetCustomersForForm(int resourceId)
		{
			return activityService.GetCustomersForForm(resourceId);
		}

		public IEnumerable<Project> GetProjectsForForm(int customerId)
		{
			return activityService.GetProjectsForForm(customerId);
		}

		public IEnumerable<Resource> GetResourcesForForm(int resourceId)
		{
			return activityService.GetResourcesForForm(resourceId);
		}

		public IEnumerable<string> GetActivityTypesForForm(int customerId)
		{
			return activityService.GetActivityTypesForForm(customerId);
		}

		public IEnumerable<Customer> GetCustomersForSearchFilter(int resourceId)
		{
			return activityService.GetCustomersForSearchFilter(resourceId);
		}

		public IEnumerable<Project> GetProjectsForSearchFilter(int customerId)
		{
			return activityService.GetProjectsForSearchFilter(customerId);
		}

		public void SaveActivity(int? activityId, string description, string activityType, int effortHours, DateTime date, int projectId, int resourceId)
		{
			activityService.SaveActivity(activityId, description, activityType, effortHours, new Date(date), projectId, resourceId);
		}

		public void ExcludeActivity(int activityId)
		{
			activityService.ExcludeActivity(activityId);
		}

		public IEnumerable<Activity> GetActivities(int resourceId, DateTime begin, DateTime end, int customerId, int projectId)
		{
			return activityService.GetActivities(resourceId, new Date(begin), new Date(end), customerId, projectId);
		}

		public Activity GetActivityById(int id)
		{
			return activityService.GetActivityById(id);
		} 
		#endregion

		#region User
		private IUserService userService;

		public bool ValidateUser(string login, string password, out User loggedUser)
		{
			return userService.ValidateUser(login, password, out loggedUser);
		}
		public void UpdateUserPassword(string login, string password, string newPassword, string newPasswordConfirmation)
		{
			userService.UpdateUserPassword(login, password, newPassword, newPasswordConfirmation);
		}
		public User GetUserByLogin(string login)
		{
			return userService.GetUserByLogin(login);
		}
		#endregion
	}
}
